package fy.hr.operator.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import fy.form.listen.operate.AForm_Save_Operator;
import fy.util.MyUtil;
import fy.hr.bean.IntegralsBean;
import fy.hr.dao.IntegralsDao;

public class IntegralsOperator extends AForm_Save_Operator {
	private List<String> personCodeList = new ArrayList<String>();
	// Begindate,Enddate,Groupdef1,Groupdef2,Groupdef3,Groupdef4
	private List<String> beginDateList = new ArrayList<String>();
	private List<String> endDateList = new ArrayList<String>();
	private List<String> groupDef1List = new ArrayList<String>();
	private List<String> groupDef2List = new ArrayList<String>();
	private List<String> groupDef3List = new ArrayList<String>();
	private List<String> groupDef4List = new ArrayList<String>();
	private List<String> groupDef5List = new ArrayList<String>();
	private List<String> groupDef6List = new ArrayList<String>();
	private List<String> groupDef7List = new ArrayList<String>();
	// private integralsBean integralsBean = new integralsBean();
	private IntegralsBean integralsBean = new IntegralsBean();
	private String pk_corp;

	private short form_type;
	// 五星班组-星级班组认证审批表
	private final static short FORM_XINGJIBANZU = 1;
	// 五星班组-五大员
	private final static short FORM_WUDAYUAN = 2;
	// 专业传承申报表
	private final static short FORM_ZHUANYE = 3;
	// 社团负责人资格认证审批表(文化贡献)
	private final static short FORM_SHETUAN = 4;
	//创新改善项目职级积分分配审批表
	private final static short FORM_GAISHAN = 5;
	//创新改善资格认证审批表 
	private final static short FORM_RENZHENG = 6;
	// 一票否决
	private final static short FORM_ONEOUT = 7;
	//奖惩类职级积分汇总
	private final static short FORM_JIANGCHENG = 8;
	//通讯稿职级积分奖励
	private final static short FORM_TONGXUN = 9;
	
	private static Log log = LogFactory.getLog(IntegralsOperator.class);

	// private static String[] corpArray = {"1025","1024", "1002", "1004",
	// "1005" };

	public String getFormName() {
		return "HR系统积分导入";
	}

	@Override
	protected void parseOtherField_FirstStep(com.seeyon.v3x.services.flow.bean.FlowExport flowExport) {
		if (templeteCode.indexOf("A") != -1) {
			form_type = FORM_XINGJIBANZU;
		} else if (templeteCode.indexOf("B") != -1) {
			form_type = FORM_WUDAYUAN;
		} else if (templeteCode.indexOf("C") != -1) {
			form_type = FORM_ZHUANYE;
		} else if (templeteCode.indexOf("D") != -1) {
			form_type = FORM_SHETUAN;
		}  else if (templeteCode.indexOf("E") != -1) {
				form_type = FORM_GAISHAN;
			} else if (templeteCode.indexOf("F") != -1) {
				form_type = FORM_RENZHENG;
			}		else if (templeteCode.indexOf("H") != -1) {
				form_type = FORM_ONEOUT;
			} else if (templeteCode.indexOf("I") != -1) {
				form_type = FORM_JIANGCHENG;
			}else if (templeteCode.indexOf("J") != -1) {
				form_type = FORM_TONGXUN;
			}else {
			System.out.println(templeteCode);
		}

		/*
		 * if (templeteCode.indexOf("C") != -1) { form_type = FORM_CHAILVFEI; }
		 * else if (templeteCode.indexOf("H") != -1) { form_type =
		 * FORM_HUIKUANDAN; }
		 */

		/*
		 * integralsBean.setPk_id(String.valueOf(UUIDLong .longUUID()));
		 * integralsBean.setOpp_acc_bank(integralsBean.getOpp_acc_bank_type() +
		 * integralsBean.getOpp_acc_bank());
		 * integralsBean.setPk_costsubj(templeteCode.indexOf("J") != -1 ? "个人借款"
		 * : (templeteCode.indexOf("C") != -1 ? "差旅费" : "3"));
		 * 
		 * integralsBean.setOperator(MyOrgManager.getInstance()
		 * .getMemberByID(flowExport.getFlowCreatePerson().getId()) .getCode());
		 * 
		 * if (templeteCode.indexOf("B") == -1) {
		 * integralsBean.setCurr_code("CNY"); }
		 */

	}

	@Override
	protected void parseValueExport(
			com.seeyon.v3x.services.form.bean.ValueExport ve) {
		String name = ve.getDisplayName();
		String value = MyUtil.replaceXMLString(ve.getValue());

		if (form_type == FORM_XINGJIBANZU) {
			if ("子公司".equals(name)) {
				integralsBean.setCompany(value);
			} else if ("认证日期".equals(name)) {
				// integralsBean.setAuthenticationDate(value);
				this.groupDef4List.add(value);
			} else if ("工号".equals(name)) {
				// integralsBean.setPsncode(value);
				this.personCodeList.add(value);
			} else if ("姓名".equals(name)) {
				integralsBean.setName(value);
			} else if ("部门".equals(name)) {
				integralsBean.setDepartment(value);
			} else if ("岗位".equals(name)) {
				integralsBean.setPosition(value);
			} else if ("所在班组".equals(name)) {
				// integralsBean.setLocatedTeam(value);
				this.groupDef2List.add(value);
			} else if ("星级班组".equals(name)) {
				// integralsBean.setStarTeam(value);
				this.groupDef1List.add(value);
			} else if ("成员角色".equals(name)) {
				// integralsBean.setMemberRole(value);
				this.groupDef3List.add(value);
			} else if ("得分".equals(name)) {
				integralsBean.setScore(value);
			} else if ("备注".equals(name)) {
				integralsBean.setRemarks(value);
			} else if ("起始日期".equals(name)) {
				// integralsBean.setBegindate(value);
				this.beginDateList.add(value);
			} else if ("终止日期".equals(name)) {
				// integralsBean.setEnddate(value);
				this.endDateList.add(value);
			}
		} else if (form_type == FORM_WUDAYUAN) {

			if ("工号".equals(name)) {
				// integralsBean.setPsncode(value);
				this.personCodeList.add(value);
			} else if ("班组".equals(name)) {
				// integralsBean.setLocatedTeam(value);
				this.groupDef2List.add(value);
			} else if ("五星班组职务".equals(name)) {
				// integralsBean.setMemberRole(value);
				this.groupDef3List.add(value);
			} else if ("任职日期".equals(name)) {
				// integralsBean.setBegindate(value);
				this.beginDateList.add(value);
			} else if ("免职日期".equals(name)) {
				// integralsBean.setEnddate(value);
				this.endDateList.add(value);
			}

		} else if (form_type == FORM_ZHUANYE) {

			if ("工号".equals(name)) {
				// integralsBean.setPsncode(value);
				this.personCodeList.add(value);
			} else if ("发布时间".equals(name)) {
				this.groupDef1List.add(value);
			} else if ("是否新编".equals(name)) {
				// integralsBean.setLocatedTeam(value);
				this.groupDef2List.add(value);
			} else if ("文件类型".equals(name)) {
				this.groupDef3List.add(value);
			} else if ("是否已签批发布".equals(name)) {
				// integralsBean.setMemberRole(value);
				this.groupDef4List.add(value);
			} else if ("起始日期".equals(name)) {
				// integralsBean.setBegindate(value);
				this.beginDateList.add(value);
			} else if ("终止日期".equals(name)) {
				// integralsBean.setEnddate(value);
				this.endDateList.add(value);
			}
			// ------------------------
			else if ("文件名称".equals(name)) {
				// integralsBean.setEnddate(value);
				this.groupDef5List.add(value);
			}
		}

		else if (form_type == FORM_SHETUAN) {

			if ("工号".equals(name)) {
				// integralsBean.setPsncode(value);
				this.personCodeList.add(value);
			} else if ("社团职务".equals(name)) {
				// integralsBean.setLocatedTeam(value);
				this.groupDef1List.add(value);
			} else if ("任职日期".equals(name)) {
				// integralsBean.setBegindate(value);
				this.beginDateList.add(value);
			} else if ("免职日期".equals(name)) {
				// integralsBean.setEnddate(value);
				this.endDateList.add(value);
			}
			// -----------------------
			else if ("负责社团名称".equals(name)) {
				this.groupDef3List.add(value);
				System.err.println(this.groupDef3List.add(value));
			}

		} else if (form_type == FORM_GAISHAN) {

			if ("工号".equals(name)) {
				this.personCodeList.add(value);
			} else if ("提案-项目类型".equals(name)) {
				this.groupDef1List.add(value);
			} else if ("贡献率".equals(name)) {
				this.groupDef2List.add(value);
			} else if ("奖励等级".equals(name)) {
				this.groupDef3List.add(value);
			} else if ("提案-项目名称".equals(name)) {
				this.groupDef4List.add(value);
			}
			// -----------------------------
			else if ("提案-项目结案时间".equals(name)) {
				this.groupDef5List.add(value);
			} 
//			else if ("系数1".equals(name)) {
//				this.groupDef6List.add(value);
//			}

		} else if (form_type == FORM_RENZHENG) {
			if ("工号".equals(name)) {
				this.personCodeList.add(value);
			} else if ("认证时间1".equals(name)) {
				this.beginDateList.add(value);
			} else if ("创新资格等级".equals(name)) {
				this.groupDef3List.add(value);
			}
			// ------------------------
			else if ("提案-项目名称".equals(name)) {
				this.groupDef4List.add(value);
			} else if ("资格有效期1".equals(name)) {
				this.groupDef5List.add(value);
			}

		}
		// ------------------------
		else if (form_type == FORM_ONEOUT) {
			if ("工号".equals(name)) {
				this.personCodeList.add(value);
			} else if ("发生时间".equals(name)) {
				this.beginDateList.add(value);
			} else if ("取消当年度职级评审因素".equals(name)) {
				this.groupDef1List.add(value);
			} else if ("详细原因".equals(name)) {
				this.groupDef2List.add(value);
			} else if ("影响周期".equals(name)) {
				this.groupDef3List.add(value);
			} else if ("数据来源".equals(name)) {
				this.groupDef4List.add(value);
			}
		}
			else if(form_type==FORM_JIANGCHENG){
			log.info(name +"==--->>>"+value);
//				System.err.println("111");
				if ("人员编码".equals(name)) {
					this.personCodeList.add(value);
				}else if ("奖惩类型".equals(name)) {
					this.groupDef1List.add(value);
				} else if ("奖惩等级".equals(name)) {
					this.groupDef2List.add(value);
				} else if ("是否为个人奖项".equals(name)) {
					this.groupDef3List.add(value);
				} else if ("奖惩单位".equals(name)) {
					this.groupDef4List.add(value);
				} else if ("奖惩日期".equals(name)) {
					this.beginDateList.add(value);
				}else if ("奖惩事由".equals(name)) {
					this.groupDef5List.add(value);
				}else if ("奖惩项目".equals(name)) {
					this.groupDef7List.add(value);
				}
			}
			else if(form_type==FORM_TONGXUN){
				if ("人员编码".equals(name)) {
					this.personCodeList.add(value);
				}else if ("通讯稿类型".equals(name)) {
					this.groupDef1List.add(value);
				}else if ("刊登时间".equals(name)) {
					this.beginDateList.add(value);
				}
			}else{	System.out.println("没调到");
			}
			/*
			 * //integralsBean.setBegindate(value);
			 * this.beginDateList.add(value); } else if ("免职日期".equals(name)) {
			 * // integralsBean.setEnddate(value); this.endDateList.add(value);
			 * }
			 */

	
		/*
		 * } else { if ("单据编号".equals(name)) {
		 * integralsBean.setBill_no(templeteCode.charAt(2) + value); } else if
		 * ("单位选择器".equals(name)) {
		 * integralsBean.setPk_corp(OA_UAPAccountContrast
		 * .getUapAccountID(value)); if (templeteCode.indexOf("B") == -1) {
		 * integralsBean.setOpp_corp(OA_UAPAccountContrast
		 * .getAccountNameByOAID(value)); } } else if ("日期".equals(name) ||
		 * "填写日期".equals(name)) { if (templeteCode.indexOf("B") == -1) {
		 * integralsBean.setBill_date(MyUtil.getDate(value)); }
		 * integralsBean.setOperator_date(MyUtil.getDate(value)); } else if
		 * ("付款日期".equals(name) && templeteCode.indexOf("B") != -1) {
		 * integralsBean.setBill_date(MyUtil.getDate(value)); } else if
		 * ("币种1".equals(name) && templeteCode.indexOf("B") != -1) {
		 * integralsBean.setCurr_code(value); } else if ("小写金额".equals(name) ||
		 * "金额小写".equals(name)) { integralsBean.setBill_amount(value); } else if
		 * ("已预付".equals(name) && templeteCode.indexOf("B") != -1 ||
		 * "预付金额".equals(name) && templeteCode.indexOf("C") != -1) {
		 * integralsBean.setAdv_amount(value); } else if ("借款人".equals(name) ||
		 * "收款人".equals(name)) { integralsBean.setOpp_acc_name(value); } else if
		 * ("收款单位".equals(name)) { integralsBean.setOpp_corp(value);
		 * integralsBean.setOpp_acc_name(value); } else if
		 * ("借款人工资卡号".equals(name) || "账号".equals(name)) {
		 * integralsBean.setOpp_acc_no(value); } else if ("开户行1".equals(name)) {
		 * integralsBean.setOpp_acc_bank_type(value); } else if
		 * ("分行_支行_分理处_".equals(name)) { integralsBean.setOpp_acc_bank(value); }
		 * else if ("摘要".equals(name)) { integralsBean.setAbs(value); } else if
		 * ("凭证张数_".equals(name) || "附票据张数".equals(name)) {
		 * integralsBean.setVoucher_count(value); } else if
		 * ("报销类型1".equals(name)) { integralsBean.setCostsubj(value); } else if
		 * ("所属制造部".equals(name)) { pk_corp = value; } }
		 */
	}

	@Override
	protected boolean save() {
		log.info("save----->>>>");
		integralsBean.setPersonCodeList(this.personCodeList);
		integralsBean.setGroupDef1List(this.groupDef1List);
		integralsBean.setGroupDef2List(this.groupDef2List);
		integralsBean.setGroupDef3List(this.groupDef3List);
		integralsBean.setGroupDef4List(this.groupDef4List);
		integralsBean.setGroupDef7List(this.groupDef7List);
		integralsBean.setBeginDateList(this.beginDateList);
		integralsBean.setEndDateList(this.endDateList);
		// -------------
		integralsBean.setGroupDef5List(this.groupDef5List);
		integralsBean.setGroupDef6List(this.groupDef6List);
		IntegralsDao integralsDao = new IntegralsDao();
		integralsDao.setIntegralsBean(integralsBean);
		integralsDao.insertStarA(form_type);
		return true;

		// //非总办、万达、福清巴士，不写入
		// if (MyUtil.indexOf(corpArray, integralsBean.getPk_corp()) == -1) {
		// return true;
		// }

		/*
		 * if ("3".equals(integralsBean.getPk_costsubj())) {
		 * integralsBean.setPk_costsubj(integralsBean.getCostsubj()); }
		 * integralsBean.setPk_costsubj(MyUtil.replaceXMLString(integralsBean
		 * .getPk_costsubj()));
		 * 
		 * if (pk_corp != null) { integralsBean.setPk_corp(pk_corp); }
		 * 
		 * FundsDao dao = new FundsDao();
		 * 
		 * dao.setFundsBean(integralsBean); String msg = null; if
		 * (integralsBean.getOperator() == null ||
		 * "".equals(integralsBean.getOperator())) { msg = new
		 * StringBuilder().append("《")
		 * .append(super.formBean.getFlowExport().getFlowTitle())
		 * .append("》写入UAP失败，需要手工将数据录入到资金系统。单据编号：")
		 * .append(integralsBean.getBill_no()).append("。原因：填单人员工号为空。")
		 * .toString(); } else { try { if (dao.save()) { return true; } else {
		 * msg = new StringBuilder().append("《")
		 * .append(super.formBean.getFlowExport().getFlowTitle())
		 * .append("》写入UAP失败，需要手工将数据录入到资金系统。单据编号：")
		 * .append(integralsBean.getBill_no()).append("。原因：写入数据库异常。")
		 * .toString();
		 * 
		 * } } catch (Exception e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); } } MessageSender.sendMsg(new long[] {
		 * super.formBean.getFlowExport().getFlowCreatePerson().getId(),
		 * super.formBean.getOperatorID() }, msg);
		 * LogWriter.writeLog(MyUtil.getRealPath(this.getClass()), msg);
		 * log.error(msg); return false;
		 */
	}
}
